/*
Simple Forum Auto Poster.
Copyright (C) 2011 Gianni Van Hoecke.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package domain.forumdata;

import domain.forumdata.tag.Tag;
import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author Gianni Van Hoecke <gianni.vh@gmail.com>
 * Abstract class that is the base of every forum implementation.
 */
public abstract class Forum implements Serializable
{
    private String forumType;
    private String forumName;
    private String loginURL;
    private String username;
    private char[] password;
    private ArrayList<ForumCategory> categories;

    /**
     * Default constructor. Initializes a new forum.
     * @param forumType The type of the forum.
     * @param forumName The name for the forum.
     * @param loginURL The login URL of the forum.
     * @param username The username.
     * @param password The password.
     * @param categories A list of assigned categories.
     * @see SupportedForums
     * @see ForumCategory
     */
    public Forum(String forumType, String forumName, String loginURL, String username, char[] password, ArrayList<ForumCategory> categories)
    {
        this.forumType = forumType;
        this.forumName = forumName;
        this.loginURL = loginURL;
        this.username = username;
        this.password = password;
        this.categories = categories;
    }

    /**
     * Starts posting to the forum.
     * @param cat The category to post to.
     * @param topicTitle The topic title of the new post.
     * @param topicSubtitle The topic subtitle or small description of the new post.
     * @param tag The tag to use.
     * @param post The post body of the new post.
     * @return True if the message has been posted, false otherwise.
     */
    public abstract boolean doPost(Category cat, String topicTitle, String topicSubtitle, Tag tag, String post);

    /**
     * Tries to login at the forum.
     * @return True if the login was succesful, false otherwise.
     */
    public abstract boolean canLogin();

    /**
     * @return a list of assigned categories.
     * @see ForumCategory
     */
    public ArrayList<ForumCategory> getCategories()
    {
        return categories;
    }

    /**
     * Sets the assigned categories.
     * @param categories The assigned categories.
     * @see ForumCategory
     */
    public void setCategories(ArrayList<ForumCategory> categories)
    {
        this.categories = categories;
    }

    /**
     * @return The name of this forum.
     */
    public String getForumName()
    {
        return forumName;
    }

    /**
     * Sets the name of this forum.
     * @param forumName The new name.
     */
    public void setForumName(String forumName)
    {
        this.forumName = forumName;
    }

    /**
     * @return The password of this forum.
     */
    public char[] getPassword()
    {
        return password;
    }

    /**
     * Sets the password of this forum.
     * @param password The new password.
     */
    public void setPassword(char[] password)
    {
        this.password = password;
    }

    /**
     * @return The username of this forum.
     */
    public String getUsername()
    {
        return username;
    }

    /**
     * Sets the username of this forum.
     * @param username The new username.
     */
    public void setUsername(String username)
    {
        this.username = username;
    }

    /**
     * @return The login URL of this forum.
     */
    public String getLoginURL()
    {
        return loginURL;
    }

    /**
     * Sets the login URL of this forum.
     * @param loginURL The new URL.
     */
    public void setLoginURL(String loginURL)
    {
        this.loginURL = loginURL;
    }

    /**
     * @return The forum type.
     */
    public String getForumType()
    {
        return forumType;
    }

    /**
     * Checks whether this forum has the specified category or not.
     * @param cat The category to look for.
     * @return True if this forum has the specified category, false otherwise.
     */
    public boolean hasCategory(Category cat)
    {
        for(ForumCategory fc : this.categories)
        {
            if(fc.getCategory().getName().equals(cat.getName()))
                return true;
        }
        return false;
    }
}